<?php

use Workerman\Worker;
use Workerman\Crontab\Crontab;

require_once __DIR__ . '/vendor/autoload.php';

//设置时区
date_default_timezone_set('PRC');

echo date('Y-m-d H:i:s');

$worker = new Worker();

$crontab = null;

$worker->onWorkerStart = function ($task){

    global $crontab;
    //每分钟的第一秒执行
    $crontab = new Crontab('1 * * * * *', function () {
        echo date('Y-m-d H:i:s') . "\n";
    });

    // 每天的7点50执行，注意这里省略了秒位.
    new Crontab('50 7 * * *', function(){
        echo date('Y-m-d H:i:s')."\n";
    });

};

//删除定时器呢
$worker->onWorkerStop = function ($task){
    global $crontab;    //全局变量
    $crontab->del();
};

Worker::runAll();